package top.zerozoo.learn.grade.service.impl;

import top.zerozoo.learn.grade.dao.StudentDao;
import top.zerozoo.learn.grade.entity.Student;
import top.zerozoo.learn.grade.factory.DaoFactory;
import top.zerozoo.learn.grade.service.StudentService;
import top.zerozoo.learn.grade.vo.StudentInfo;

public class StudentServiceImpl implements StudentService {
    private final StudentDao studentDao = DaoFactory.get(StudentDao.class);

    @Override
    public StudentInfo find(int id) {
        if (id < 0) {
            return null;
        }
        Student student = studentDao.findById(id);
        return student != null ? StudentInfo.parse(student) : null;

    }

    @Override
    public boolean update(Student student) {
        return studentDao.update(student) != 0;
    }

    @Override
    public boolean insert(Student student) {
       return studentDao.insert(student) != 0;
    }

    @Override
    public boolean delete(int id) {
        if (id < 0) {
            return false;
        }
        return studentDao.deleteById(id) != 0;
    }
}
